package com.qidian.k12.util;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 返回值格式
 *
 * @author Hello
 */
public class K12Result {
    private int status;
    private String msg;
    private Object data;

    /**
     * 常量
     */
    public static class ResultStatus {
        public static final int OK = 200;
        public static final int ERROR = 500;
        public static final int NOT_FOND = 404;
        public static final int DATA_EXISTS = 505;
        public static final int OK_PART = 205;
        public static final String OK_PART_MSG = "ok part";
        public static final String OK_MSG = "ok";
        public static final String ERROR_MSG = "error";
        public static final String NOT_FOND_MSG = "not fond";
        public static final String DATA_EXISTS_MSG = "data exists";

    }

    public static K12Result noFond(){
        K12Result noFond=new K12Result();
        noFond.setStatus(ResultStatus.NOT_FOND);
        noFond.setMsg(ResultStatus.NOT_FOND_MSG);
        return noFond;
    }

    /**
     * 200
     *
     * @return
     */
    public static K12Result ok() {
        K12Result ok = new K12Result();
        ok.setStatus(ResultStatus.OK);
        ok.setMsg(ResultStatus.OK_MSG);

        return ok;
    }

    /**
     *
     * @param object
     * @return
     */
    public static K12Result ok(Object object) {
        K12Result ok = new K12Result();
        ok.setStatus(ResultStatus.OK);
        ok.setMsg(ResultStatus.OK_MSG);
        ok.setData(object);
        return ok;
    }


    /**
     * 500
     *
     * @return
     */
    public static K12Result error() {
        K12Result error = new K12Result();
        error.setStatus(ResultStatus.ERROR);
        error.setMsg(ResultStatus.ERROR_MSG);
        return error;
    }

    /**
     * 505
     *
     * @return
     */
    public static K12Result dataEXists() {
        K12Result dataExists = new K12Result();
        dataExists.setStatus(ResultStatus.DATA_EXISTS);
        dataExists.setMsg(ResultStatus.DATA_EXISTS_MSG);
        return dataExists;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
